class VailsController < ApplicationController
	before_filter :login_required, :except => [:show]
	
  def show
    @vail = Vail.find(params[:id])
  end

  # GET /vails/1;edit
  def edit
    @vail = Vail.find(params[:id])
  end

  def create
    @vail = Vail.new(params[:vail])

    respond_to do |format|
      if @vail.save
        flash[:notice] = 'Vail was successfully created.'
        format.html { redirect_to vail_url(@vail) }
        format.xml  { head :created, :location => vail_url(@vail) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @vail.errors.to_xml }
      end
    end
  end

  # PUT /vails/1
  # PUT /vails/1.xml
  def update
		params[:vail][:datasheet_ids] ||= []
    @vail = Vail.find(params[:id])

    respond_to do |format|
      if @vail.update_attributes(params[:vail])
        flash[:notice] = 'Vail was successfully updated.'
        format.html { redirect_to path_for_vail(@vail) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @vail.errors.to_xml }
      end
    end
  end

  # DELETE /vails/1
  # DELETE /vails/1.xml
  def destroy
    @vail = Vail.find(params[:id])
    @vail.destroy

    respond_to do |format|
      format.html { redirect_to vails_url }
      format.xml  { head :ok }
    end
  end
end
